<div class="tabbable tabs-left">
    <ul class="nav nav-tabs">
        <li><h5><?php echo $this->translate('优惠券'); ?></h5></li>
        <li class="active"><a data-toggle="tab" href="#coupon_a"><?php echo $this->translate('基本信息'); ?></a></li>
        <li class=""><a data-toggle="tab" href="#coupon_c"><?php echo $this->translate('优惠规则'); ?></a></li>
        <li class=""><a data-toggle="tab" href="#coupon_b"><?php echo $this->translate('获取规则'); ?></a></li>
        <li class=""><a data-toggle="tab" href="#coupon_d"><?php echo $this->translate('使用规则'); ?></a></li>
    </ul>
    <form class="form-horizontal" method="post" name="coupon_add_form" id="coupon_add_form" action="">
        <input type="hidden" name="coupon_id" id="coupon_id" value="<?php echo ($this->coupon_info ? $this->coupon_info->coupon_id : ''); ?>" />
        <div class="tab-content">
            <div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
                <div class="pull-left" style="font-size:16px;line-height:30px;"><strong><?php if($this->coupon_info) echo $this->translate('编辑'); else echo $this->translate('新加'); ?><?php echo $this->translate('优惠券'); ?></strong></div>
                <div id="sticky_navigation_right" class="pull-right">
                    <a href="<?php echo $this->url('coupon/default'); ?>" class="btn btn-small"><i class="icon-arrow-left"></i> <?php echo $this->translate('返回优惠券列表'); ?></a>&nbsp;
                    <a href="<?php echo $this->serverUrl(true); ?>" class="btn btn-small btn-warning"><i class="icon-repeat icon-white"></i> <?php echo $this->translate('刷新'); ?></a>&nbsp;
                    <button type="submit" class="btn btn-small btn-primary"><i class="icon-ok icon-white"></i> <?php echo $this->translate('保存优惠券'); ?></button>&nbsp;
                    <a href="<?php echo $this->myviewalias()->dbshopHelpUrl('goods_coupon_set'); ?>" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看帮助说明'); ?></a>
                </div>
            </div>
            <div id="coupon_a" class="tab-pane active">
                <div class="well admin_add_header_well"><?php echo $this->translate('基本信息'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('优惠券名称'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <input type="text" id="coupon_name"  name="coupon_name" value="<?php echo ($this->coupon_info ? $this->escapeHtml($this->coupon_info->coupon_name) : ''); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('优惠券描述'); ?>：</label>
                        <div class="controls">
                            <input type="text" id="coupon_info"  name="coupon_info" value="<?php echo ($this->coupon_info ? $this->escapeHtml($this->coupon_info->coupon_info) : ''); ?>" class="span6"> <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('前台也会显示。'); ?>"></i>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('状态'); ?>：</label>
                        <div class="controls">
                            <select name="coupon_state" id="coupon_state" class="span2">
                                <option value="1" <?php if ($this->coupon_info and $this->coupon_info->coupon_state == 1) echo 'selected="selected"'; ?>><?php echo $this->translate('开启'); ?></option>
                                <option value="2" <?php if ($this->coupon_info and $this->coupon_info->coupon_state == 2) echo 'selected="selected"'; ?>><?php echo $this->translate('关闭'); ?></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div id="coupon_b" class="tab-pane">
                <div class="well admin_add_header_well"><?php echo $this->translate('获取规则'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('开始时间'); ?>：</label>
                        <div class="controls">
                            <input type="text" id="get_coupon_start_time"  name="get_coupon_start_time" value="<?php if ($this->coupon_info and $this->coupon_info->get_coupon_start_time != '') echo date("Y-m-d H:i:s",$this->coupon_info->get_coupon_start_time); ?>" onclick="WdatePicker({el:'get_coupon_start_time', dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="span2 Wdate"> <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('请在此填写有效的开始时间，为空，则不限时间。'); ?>"></i>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('结束时间'); ?>：</label>
                        <div class="controls">
                            <input type="text" id="get_coupon_end_time"  name="get_coupon_end_time" value="<?php if ($this->coupon_info and $this->coupon_info->get_coupon_end_time != '') echo date("Y-m-d H:i:s",$this->coupon_info->get_coupon_end_time); ?>" onclick="WdatePicker({el:'get_coupon_end_time', dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="span2 Wdate"> <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('请在此填写有效的结束时间，为空，则不限时间。'); ?>"></i>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('获取方式'); ?>：</label>
                        <div class="controls">
                            <select name="get_coupon_type" id="get_coupon_type" class="span2" onchange="select_coupon_type();">
                                <option value="buy" <?php if ($this->coupon_info and $this->coupon_info->get_coupon_type == 'buy') echo 'selected="selected"'; ?>><?php echo $this->translate('购物直接获取'); ?></option>
                                <option value="click" <?php if ($this->coupon_info and $this->coupon_info->get_coupon_type == 'click') echo 'selected="selected"'; ?>><?php echo $this->translate('点击直接获取(登录用户)'); ?></option>
                                <option value="register" <?php if ($this->coupon_info and $this->coupon_info->get_coupon_type == 'register') echo 'selected="selected"'; ?>><?php echo $this->translate('注册直接获取'); ?></option>
                            </select>
                        </div>
                    </div>
                    <div class="control-group get_shopping_amount">
                        <label for="input01" class="control-label"><?php echo $this->translate('购物满'); ?>：</label>
                        <div class="controls">
                            <input type="text" name="get_shopping_amount" id="get_shopping_amount" value="<?php echo ($this->coupon_info ? $this->coupon_info->get_shopping_amount : ''); ?>" class="span2"> <?php echo $this->translate('元 获得优惠券'); ?>
                        </div>
                    </div>
                    <div class="control-group set_user_type">
                        <label for="input01" class="control-label"><?php echo $this->translate('指定客户组'); ?>：</label>
                        <div class="controls">
                            <select name="get_user_type" id="get_user_type" class="span2" onchange="select_user('get_user_type', 'get_user_group');">
                                <option value="all_user" <?php if ($this->coupon_info and $this->coupon_info->get_user_type == 'all_user') echo 'selected="selected"'; ?>><?php echo $this->translate('所有客户'); ?></option>
                                <option value="user_group" <?php if ($this->coupon_info and $this->coupon_info->get_user_type == 'user_group') echo 'selected="selected"'; ?>><?php echo $this->translate('个性化客户组'); ?></option>
                            </select>
                        </div>
                    </div>
                    <div class="control-group get_user_type set_user_type" id="get_user_group" <?php if (($this->coupon_info and $this->coupon_info->get_user_type == 'all_user') or !isset($this->coupon_info->get_user_type)) echo 'style="display:none;"'; ?>>
                        <label for="input01" class="control-label"><?php echo $this->translate('个性化客户组'); ?>：</label>
                        <div class="controls">
                            <?php
                            $selectUserGroup = ($this->coupon_info and $this->coupon_info->get_user_group != '') ? unserialize($this->coupon_info->get_user_group) : array();
                            if ($this->group_array) {
                                foreach ($this->group_array as $group_val) {
                                    ?>
                                    <label class="checkbox"><input type="checkbox" name="get_user_group[]" <?php if(!empty($selectUserGroup) and in_array($group_val['group_id'], $selectUserGroup)) echo 'checked="checked"'; ?> value="<?php echo $group_val['group_id']; ?>" /><?php echo $this->escapeHtml($group_val['group_name']); ?></label>
                                <?php } } ?>
                        </div>
                    </div>
                    <div class="control-group set_goods_type">
                        <label for="input01" class="control-label"><?php echo $this->translate('指定商品类型'); ?>：</label>
                        <div class="controls">
                            <select name="get_goods_type" id="get_goods_type" class="span2" onchange="select_goods('get_goods_type', 'get_coupon_goods_class', 'get_coupon_goods_brand');">
                                <option value="all_goods" <?php if ($this->coupon_info and $this->coupon_info->get_goods_type == 'all_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('所有商品'); ?></option>
                                <option value="class_goods" <?php if ($this->coupon_info and $this->coupon_info->get_goods_type == 'class_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('商品分类'); ?></option>
                                <option value="brand_goods" <?php if ($this->coupon_info and $this->coupon_info->get_goods_type == 'brand_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('商品品牌'); ?></option>
                            </select>
                        </div>
                    </div>
                    <?php
                    $selectGetGoodsType = ($this->coupon_info and $this->coupon_info->get_coupon_goods_body != '') ? unserialize($this->coupon_info->get_coupon_goods_body) : array();
                    ?>
                    <div class="control-group get_goods_type set_goods_type" id="get_coupon_goods_class" <?php if (($this->coupon_info and ($this->coupon_info->get_goods_type == 'all_goods' or $this->coupon_info->get_goods_type == 'brand_goods')) or !isset($this->coupon_info)) echo 'style="display:none;"'; ?>>
                        <label for="input01" class="control-label"><?php echo $this->translate('商品分类'); ?>：</label>
                        <div class="controls">
                            <?php
                            if ($this->goods_class) {
                                foreach ($this->goods_class as $class_val) {
                                    ?>
                                    <label class="checkbox"  style="margin-left:<?php echo $class_val['class_level'] * 20; ?>px;"><input type="checkbox" name="get_coupon_goods_class[]" value="<?php echo $class_val['class_id']; ?>" <?php if(!empty($selectGetGoodsType) and $this->coupon_info->get_goods_type == 'class_goods' and in_array($class_val['class_id'], $selectGetGoodsType)) echo 'checked="checked"'; ?>><?php echo $this->escapeHtml($class_val['class_name']); ?></label>
                                    <?php
                                }
                            }
                            ?>
                        </div>
                    </div>
                    <div class="control-group get_goods_type" id="get_coupon_goods_brand" <?php if (($this->coupon_info and ($this->coupon_info->get_goods_type == 'all_goods' or $this->coupon_info->get_goods_type == 'class_goods')) or !isset($this->coupon_info)) echo 'style="display:none;"'; ?>>
                        <label for="input01" class="control-label"><?php echo $this->translate('商品品牌'); ?>：</label>
                        <div class="controls">
                            <?php
                            if ($this->goods_brand) {
                                foreach ($this->goods_brand as $brand_val) {
                                    ?>
                                    <label class="checkbox"><input type="checkbox" name="get_coupon_goods_brand[]" value="<?php echo $brand_val['brand_id']; ?>" <?php if(!empty($selectGetGoodsType) and $this->coupon_info->get_goods_type == 'brand_goods' and in_array($brand_val['brand_id'], $selectGetGoodsType)) echo 'checked="checked"'; ?>><?php echo $this->escapeHtml($brand_val['brand_name']); ?></label>
                                    <?php
                                }
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>
            <div id="coupon_c" class="tab-pane">
                <div class="well admin_add_header_well"><?php echo $this->translate('优惠规则'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('购物金额满'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <input type="text" id="shopping_amount"  name="shopping_amount" value="<?php echo ($this->coupon_info ? $this->coupon_info->shopping_amount : ''); ?>" class="span2"><?php echo $this->translate('元'); ?>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('优惠(立减)'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <input type="text" id="shopping_discount"  name="shopping_discount" value="<?php echo ($this->coupon_info ? $this->coupon_info->shopping_discount : ''); ?>" class="span1">
                            <?php echo $this->translate('元'); ?>
                        </div>
                    </div>
                </div>
            </div>
            <div id="coupon_d" class="tab-pane">
                <div class="well admin_add_header_well"><?php echo $this->translate('使用规则'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('开始时间'); ?>：</label>
                        <div class="controls">
                            <input type="text" id="coupon_start_time"  name="coupon_start_time" value="<?php if ($this->coupon_info and $this->coupon_info->coupon_start_time != '') echo date("Y-m-d H:i:s",$this->coupon_info->coupon_start_time); ?>" onclick="WdatePicker({el:'coupon_start_time', dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="span2 Wdate"> <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('请在此填写有效的开始时间，为空，则不限时间。'); ?>"></i>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('结束时间'); ?>：</label>
                        <div class="controls">
                            <input type="text" id="coupon_end_time"  name="coupon_end_time" value="<?php if ($this->coupon_info and $this->coupon_info->coupon_end_time != '') echo date("Y-m-d H:i:s",$this->coupon_info->coupon_end_time); ?>" onclick="WdatePicker({el:'coupon_end_time', dateFmt:'yyyy-MM-dd HH:mm:ss'})" class="span2 Wdate"> <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('请在此填写有效的结束时间，为空，则不限时间。'); ?>"></i>
                        </div>
                    </div>
                    <?php
                    $useChannel = array();
                    if($this->coupon_info and !empty($this->coupon_info->coupon_use_channel)) {
                        $useChannel = unserialize($this->coupon_info->coupon_use_channel);
                    }
                    ?>
                    <!--div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('使用渠道'); ?>：</label>
                        <div class="controls">
                            <label class="checkbox inline"><input type="checkbox" name="coupon_use_channel[]" value="pc" <?php if(!empty($useChannel) and @in_array('pc', $useChannel)) echo 'checked'; ?>><?php echo $this->translate('PC'); ?></label>
                            <label class="checkbox inline"><input type="checkbox" name="coupon_use_channel[]" value="phone" <?php if(!empty($useChannel) and @in_array('phone', $useChannel)) echo 'checked'; ?>><?php echo $this->translate('微信(手机)'); ?></label>
                            <label class="checkbox inline"><input type="checkbox" name="coupon_use_channel[]" value="app" <?php if(!empty($useChannel) and @in_array('app', $useChannel)) echo 'checked'; ?>><?php echo $this->translate('APP'); ?></label>
                        </div>
                    </div-->
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('指定商品类型'); ?>：</label>
                        <div class="controls">
                            <select name="coupon_goods_type" id="coupon_goods_type" class="span2" onchange="select_goods('coupon_goods_type', 'coupon_goods_class', 'coupon_goods_brand');">
                                <option value="all_goods" <?php if ($this->coupon_info and $this->coupon_info->coupon_goods_type == 'all_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('所有商品'); ?></option>
                                <option value="individual_goods" <?php if ($this->coupon_info and $this->coupon_info->coupon_goods_type == 'individual_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('个别商品'); ?></option>
                                <option value="class_goods" <?php if ($this->coupon_info and $this->coupon_info->coupon_goods_type == 'class_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('商品分类'); ?></option>
                                <option value="brand_goods" <?php if ($this->coupon_info and $this->coupon_info->coupon_goods_type == 'brand_goods') echo 'selected="selected"'; ?>><?php echo $this->translate('商品品牌'); ?></option>
                            </select>
                        </div>
                    </div>
                    <?php
                    $selectGoodsType = ($this->coupon_info and $this->coupon_info->coupon_goods_body != '') ? unserialize($this->coupon_info->coupon_goods_body) : array();
                    ?>
                    <div class="control-group coupon_goods_type" id="coupon_individual_goods" <?php if (($this->coupon_info and $this->coupon_info->coupon_goods_type != 'individual_goods') or !isset($this->coupon_info)) echo 'style="display:none;"'; ?>>
                        <label for="input01" class="control-label"><?php echo $this->translate('添加商品'); ?>：</label>
                        <div class="controls">
                            <div class="control-group">
                                <input type="text" placeholder="<?php echo $this->translate('请输入需要添加的商品部分或者全部名称'); ?>" id="individual_goods_keyword" name="individual_goods_keyword"  value="" class="span5"><input type="hidden" name="individual_goods_id" id="individual_goods_id" value="" />&nbsp;&nbsp;<button type="button" onclick="add_individual_goods_js();" class="btn btn-small btn-primary"><i class="icon-plus icon-white"></i> <?php echo $this->translate('点击添加商品'); ?></button>
                                <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('在输入框中输入商品部分或者全部名称，然后点击添加按钮，即可添加商品'); ?>"></i>
                            </div>
                            <table class="table table-hover" id="individual_goods_table">
                                <thead style="background:#CCC;">
                                <tr>
                                    <th width="5%">ID</th>
                                    <th width="35%"><?php echo $this->translate('商品名称'); ?></th>
                                    <th width="12%"><?php echo $this->translate('商品货号'); ?></th>
                                    <th width="12%"><?php echo $this->translate('商品价格'); ?></th>
                                    <th width="7%"><?php echo $this->translate('状态'); ?></th>
                                    <th width="6%"><?php echo $this->translate('操作'); ?></th>
                                </tr>
                                </thead>
                                <?php
                                if(isset($this->goods_list)) {
                                    foreach($this->goods_list as $goodsValue) {
                                ?>
                                        <tr id="show_individual_goods_<?php echo $goodsValue['goods_id']; ?>">
                                            <td><?php echo $goodsValue['goods_id']; ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue['goods_name']); ?></td>
                                            <td><?php echo $goodsValue['goods_item']; ?></td>
                                            <td><?php echo $goodsValue['goods_shop_price']; ?></td>
                                            <td><?php echo $goodsValue['goods_state'] == 1 ? $this->translate('上架') : $this->translate('下架'); ?></td>
                                            <td><input type="hidden" name="coupon_goods_id[]" value="<?php echo $goodsValue['goods_id']; ?>"><a href="javascript:;" onclick="delete_individual_goods(<?php echo $goodsValue['goods_id']; ?>);"><?php echo $this->translate('删除'); ?></a></td>
                                        </tr>
                                <?php
                                    }
                                }
                                ?>
                            </table>
                        </div>
                    </div>

                    <div class="control-group coupon_goods_type" id="coupon_goods_class" <?php if (($this->coupon_info and $this->coupon_info->coupon_goods_type != 'class_goods') or !isset($this->coupon_info)) echo 'style="display:none;"'; ?>>
                        <label for="input01" class="control-label"><?php echo $this->translate('商品分类'); ?>：</label>
                        <div class="controls">
                            <?php
                            if ($this->goods_class) {
                                foreach ($this->goods_class as $class_val) {
                                    ?>
                                    <label class="checkbox"  style="margin-left:<?php echo $class_val['class_level'] * 20; ?>px;"><input type="checkbox" name="class_id[]" value="<?php echo $class_val['class_id']; ?>" <?php if(!empty($selectGoodsType) and $this->coupon_info->coupon_goods_type == 'class_goods' and in_array($class_val['class_id'], $selectGoodsType)) echo 'checked="checked"'; ?>><?php echo $this->escapeHtml($class_val['class_name']); ?></label>
                                    <?php
                                }
                            }
                            ?>
                        </div>
                    </div>
                    <div class="control-group coupon_goods_type" id="coupon_goods_brand" <?php if (($this->coupon_info and $this->coupon_info->coupon_goods_type != 'brand_goods') or !isset($this->coupon_info)) echo 'style="display:none;"'; ?>>
                        <label for="input01" class="control-label"><?php echo $this->translate('商品品牌'); ?>：</label>
                        <div class="controls">
                            <?php
                            if ($this->goods_brand) {
                                foreach ($this->goods_brand as $brand_val) {
                                    ?>
                                    <label class="checkbox"><input type="checkbox" name="brand_id[]" value="<?php echo $brand_val['brand_id']; ?>" <?php if(!empty($selectGoodsType) and $this->coupon_info->coupon_goods_type == 'brand_goods' and in_array($brand_val['brand_id'], $selectGoodsType)) echo 'checked="checked"'; ?>><?php echo $this->escapeHtml($brand_val['brand_name']); ?></label>
                                    <?php
                                }
                            }
                            ?>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </form>
</div>
<link href="<?php echo $this->basePath('public/js/jquery-autocomplete/jquery.autocomplete.css'); ?>" rel="stylesheet">
<script src="<?php echo $this->basePath('public/js/jquery-autocomplete/jquery.autocomplete.min.js'); ?>"></script>
<script src="<?php echo $this->basePath('/public/js/DatePicker/WdatePicker.js'); ?>"></script>
<script>
    $(document).ready(function() {
        $("#coupon_add_form").validate({
            rules: {
                coupon_name: {
                    required: true
                },
                shopping_amount: {
                    required: true,
                    number: true,
                    min:1
                },
                shopping_discount: {
                    required: true,
                    number: true,
                    min:1
                }
            },
            messages: {
                coupon_name: {
                    required: "<?php echo $this->translate('优惠券名称不能为空！'); ?>"
                },
                shopping_amount: {
                    required: "<?php echo $this->translate('购物金额满不能为空！'); ?>",
                    number: "<?php echo $this->translate('购物金额满必须为数字！'); ?>",
                    min:"<?php echo $this->translate('数字最小为1'); ?>"
                },
                shopping_discount: {
                    required: "<?php echo $this->translate('优惠立减不能为空！'); ?>",
                    number: "<?php echo $this->translate('优惠立减必须为数字！'); ?>",
                    min:"<?php echo $this->translate('数字最小为1'); ?>"
                }
            }
        });
    });

    <?php if ($this->success_msg != '') { ?>
    show_message('.message_one','<?php echo date("Y-m-d H:i:s"); ?>','<?php echo $this->success_msg; ?>','alert-success');
    <?php } ?>

    //商品js处理
    function select_goods(goods_type, goods_class_html_id, goods_brand_html_id) {
        var goods_type_value = $('#'+goods_type).val();
        $('.'+goods_type).css('display', 'none');

        if(goods_type_value == 'class_goods') {
            $('#'+goods_class_html_id).css('display', '');
        }else if (goods_type_value == 'brand_goods') {
            $('#'+goods_brand_html_id).css('display', '');
        }else if(goods_type_value == 'individual_goods') {
            $('#coupon_individual_goods').css('display', '');
        }
    }
    //会员js处理
    function select_user(user_type, user_type_html_id) {
        var user_type_value = $('#'+user_type).val();
        $('.'+user_type).css('display', 'none');

        if(user_type_value == 'user_group') {
            $('#'+user_type_html_id).css('display', '');
        }
    }
    //获取方式的js处理
    function select_coupon_type() {
        var coupon_type = $('#get_coupon_type').val();
        if(coupon_type == 'register') {
            $('.set_user_type').css('display', 'none');
            $('.set_goods_type').css('display', 'none');
            $('.get_shopping_amount').css('display', 'none');
        } else {
            if(coupon_type == 'click') {
                $('.set_goods_type').css('display', 'none');
            } else {
                $('.set_goods_type').css('display', '');
                select_goods('get_goods_type', 'get_coupon_goods_class', 'get_coupon_goods_brand');
            }

            $('.set_user_type').css('display', '');
            select_user('get_user_type', 'get_user_group');

            if(coupon_type == 'buy') {
                $('.get_shopping_amount').css('display', '');
            } else {
                $('.get_shopping_amount').css('display', 'none');
            }
        }
    }
    <?php if($this->coupon_info) { ?>
    select_coupon_type();
    <?php } ?>

    //jquery-autocomplete查询商品
    $("#individual_goods_keyword").autocomplete("<?php echo $this->url('goods/default',array('action'=>'autocompleteGoodsSearch')); ?>", {
        //mustMatch: true,
        max: 20,
        minChars:1,
        scrollHeight:400
    });
    $("#individual_goods_keyword").result(function(event, data, formatted) {
        if (data) $("#individual_goods_id").val(data[1]);
    });
    //添加个别商品
    function add_individual_goods_js() {
        var individual_goods_id = $('#individual_goods_id').val();
        if(individual_goods_id == '') {
            alert('<?php echo $this->translate('该商品不存在，请从新选择！'); ?>');
            return false;
        }
        $.post("<?php echo $this->url('coupon/default',array('action'=>'oneGoods')); ?>",{goods_id:individual_goods_id},
            function(data){
                if(data.state == 'true') {
                    var html_table = '<tr id="show_individual_goods_'+data.goods_id+'">';
                    html_table = html_table + '<td>'+data.goods_id+'</td>';
                    html_table = html_table + '<td>'+data.goods_name+'</td>';
                    html_table = html_table + '<td>'+data.goods_item+'</td>';
                    html_table = html_table + '<td>'+data.goods_shop_price+'</td>';
                    html_table = html_table + '<td>'+data.goods_state+'</td>';
                    html_table = html_table + '<td><input type="hidden" name="coupon_goods_id[]" value="'+data.goods_id+'"><a href="javascript:;" onclick="delete_individual_goods('+data.goods_id+');"><?php echo $this->translate('删除'); ?></a></td>';
                    html_table = html_table + '</tr>';
                    $('#individual_goods_table').prepend(html_table);
                    $('#individual_goods_keyword').val('');
                    $('#individual_goods_id').val('');
                } else {
                    alert('<?php echo $this->translate('商品添加失败！'); ?>');
                }
            },'json');
    }
    //删除相关商品
    function delete_individual_goods(goods_id) {
        if(window.confirm('<?php echo $this->translate('您确实要删除该商品吗？'); ?>')) {
            $("#show_individual_goods_"+goods_id).remove();
        }
    }
</script>
